package classes;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class Employe.
 * 
 * @see classes.Employe
 * @author MyEclipse Persistence Tools
 */

public class EmployeDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(EmployeDAO.class);

	// property constants
	public static final String NOM = "nom";

	public static final String LOGIN = "login";
	
	public static final String PRENOM = "prenom";

	public static final String MAIL = "mail";

	public static final String CONTRAT_HORAIRE = "contratHoraire";

	public static final String ID_CONTRAT = "idContrat";

	public static final String PWD = "pwd";

	public static final String SEXE = "sexe";

	public static final String ADDRESSE = "addresse";

	public static final String TELEPHONE = "telephone";


	public void save(Employe transientInstance) {
		log.debug("saving Employe instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Employe persistentInstance) {
		log.debug("deleting Employe instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Employe findById(java.lang.Integer id) {
		log.debug("getting Employe instance with id: " + id);
		try {
			Employe instance = (Employe) getSession()
					.get("classes.Employe", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Employe instance) {
		log.debug("finding Employe instance by example");
		try {
			List results = getSession().createCriteria("classes.Employe").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Employe instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Employe as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByNom(Object nom) {
		return findByProperty(NOM, nom);
	}

	public List findByPrenom(Object prenom) {
		return findByProperty(PRENOM, prenom);
	}

	public List findByMail(Object mail) {
		return findByProperty(MAIL, mail);
	}

	public List findByLogin(Object login) {
		return findByProperty(LOGIN, login);
	}

	public List findByContratHoraire(Object contratHoraire) {
		return findByProperty(CONTRAT_HORAIRE, contratHoraire);
	}

	public List findByIdContrat(Object idContrat) {
		return findByProperty(ID_CONTRAT, idContrat);
	}

	public List findByPwd(Object pwd) {
		return findByProperty(PWD, pwd);
	}

	public List findBySexe(Object sexe) {
		return findByProperty(SEXE, sexe);
	}

	public List findByAddresse(Object addresse) {
		return findByProperty(ADDRESSE, addresse);
	}

	public List findByTelephone(Object telephone) {
		return findByProperty(TELEPHONE, telephone);
	}

	public List findAll() {
		log.debug("finding all Employe instances");
		try {
			String queryString = "from Employe";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Employe merge(Employe detachedInstance) {
		log.debug("merging Employe instance");
		try {
			Employe result = (Employe) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Employe instance) {
		log.debug("attaching dirty Employe instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Employe instance) {
		log.debug("attaching clean Employe instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}